<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";

export default {
  props: {
    probeType: {
      type: Number,
      default: 0
    },
    pullUpLoad: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      bscroll: null
    };
  },
  mounted() {
    /**
     * 滚动
     */
    // let swiper = document.querySelector(".wrapper");
    this.bscroll = new BScroll(this.$refs.wrapper, {
      click: true,
      probeType: this.probeType,
      pullUpLoad: true
    });
    if (this.probeType === 2 || this.probeType === 3) {
      this.bscroll.on("scroll", res => {
        this.$emit("scroll", res);
      });
    }
    if (this.pullUpLoad) {
      this.bscroll.on("pullingUp", () => {
        this.$emit("pullingUp");
        this.bscroll.finishPullUp();
      });
    }
  },
  methods: {
    scrollTo(x, y, time = 800) {
      this.bscroll &&
        this.bscroll.scrollTo &&
        this.bscroll.scrollTo(x, y, time);
    },
    refresh() {
      this.bscroll && this.bscroll.refresh && this.bscroll.refresh();
    },
    getScrollY() {
      return this.bscroll ? this.bscroll.y : 0;
    }
  }
};
</script>
<style scoped>
</style>